﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccessLayer;

namespace WebApplication.administrator
{
    public partial class EditUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillUserDetails();
            }
        }
        public void FillUserDetails()
        {
           int UserID =  Convert.ToInt32(Request.QueryString["ID"]);
           string Type = Request.QueryString["T"];
           AdminDisplayUserList adm = AdminUser.GetUserDeatil(UserID);
           if (null !=adm)
           {
               lblName.Text = adm.FirstName + " " + adm.LastName;
               txtFirstName.Text = adm.FirstName;
               txtLastName.Text = adm.LastName;
               txtEmailID.Text = adm.EmailID;
               txtContactNumber1.Text = adm.Mobile;
               txtContactNumber2.Text = adm.Landline;
           }
           if (Type == "V")
           {
               txtFirstName.Enabled = false;
               txtLastName.Enabled = false;
               txtContactNumber1.Enabled = false;
               txtContactNumber2.Enabled = false;
               txtEmailID.Enabled = false;
               btnSubmit.Visible = false;
           }
           else
           {
               txtEmailID.ReadOnly = true;
           }


        }
        public void btnSubmit_Click(object sender, EventArgs e)
        {
            int UserID =  Convert.ToInt32(Request.QueryString["ID"]);
            string FirstName = txtFirstName.Text.Trim();
            string LastName = txtLastName.Text.Trim();
            string Contact1 = txtContactNumber1.Text.Trim();
            string Contact2 = txtContactNumber2.Text.Trim();
            int result = AdminUser.UpdateUser(UserID, FirstName, LastName, Contact1, Contact2);
            if (result > 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "Record has been Updated Sucessfully.";
            }

        }
    }
}